﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Manage/MasterPage.master" AutoEventWireup="true" CodeFile="EditArticle.aspx.cs" Inherits="Manage_EditArticle" %>
<%@ Register Src="~/Manage/CmsMessageBox.ascx" TagName="MessageBox" TagPrefix="cms" %>
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <script type="text/javascript">
        $(document).ready(function () {
            $('#<%=SelectParent.ClientID %>').click(function () {
                var v = showModalDialog('./TopicTree.aspx', null, 'dialogWidth:400px;dialogHeight:320px;center:yes;help:yes;resizable:yes;status:no');
                var vs = v.split('|');

                if (vs[0] == 'null') {
                    $('#<%=TopicName.ClientID %>').text('请选择');
                    $('#<%=TopicID.ClientID %>').val('');
                } else {
                    $('#<%=TopicName.ClientID %>').text(vs[1]);
                    $('#<%=TopicID.ClientID %>').val(vs[0]);
                }

                return false;
            });

            $('#<%=SelectAnnex.ClientID %>').click(function () {
                var v = showModalDialog('./UploadFile.aspx?type=annex', null, 'dialogWidth:300px;dialogHeight:150px;center:yes;help:yes;resizable:yes;status:no');
                if (v != null) {
                    var vs = v.split('|');

                    $('#<%=SelectAnnex.ClientID %>').before('<span id="' + vs[0] + '" class="Annex">' + vs[1] + '</span>');
                }

                seriesAnnex();

                //设置双击事件
                $('span.Annex').dblclick(function () {
                    deleteAnnex($(this));
                });

                return false;
            });

            $('#<%=Save.ClientID %>').click(function () {
                var ds = [
                    { 'Controller': '#<%=ArticleTitle.ClientID %>',
                        'Type': 'R', 'Clear': true, 'Focus': true,
                        'ErrorMessage': '请输入文章标题。'
                    },
                    { 'Controller': '#<%=ArticleKeywords.ClientID %>',
                        'Type': 'R', 'Clear': true, 'Focus': true,
                        'ErrorMessage': '请输入文章关键字。'
                    },
                    { 'Controller': '#<%=TopicID.ClientID %>',
                        'Type': 'R', 'Clear': true, 'Focus': true,
                        'ErrorMessage': '请输入文章所属栏目。'
                    },
                    { 'Count': $('#<%=ArticleTemplates.ClientID %>').children().children().children().children(':radio:checked').size(),
                        'Type': 'C', 'ErrorMessage': '请选择静态文章所使用的模版。'
                    }
                     ];

                return Cms_ValidateForm(ds);
            });

            $('span.Annex').dblclick(function () {
                deleteAnnex($(this));
            });

            function seriesAnnex() {
                var ids = [];
                $('span.Annex').each(function () {
                    ids[ids.length] = $(this).attr('id');
                });

                $('#<%=AnnexID.ClientID %>').val(ids.join('|'));
            }

            function deleteAnnex(annex) {
                if (Cms_Confirm('确认删除选中的附件吗？')) {
                    $(annex).remove();

                    seriesAnnex();
                }
            }
        });
    </script></asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="body" Runat="Server">

    <cms:MessageBox ID="Message" runat="server" />
    <asp:HiddenField ID="ArticleID" runat="server" />
    <table class="Info" cellspacing="1">
        <tr>
            <td align="right" style="width: 100px">文章标题：</td>
            <td><asp:TextBox ID="ArticleTitle" runat="server" Width="500px"></asp:TextBox></td>
        </tr>
        <tr>
            <td align="right">文章子标题：</td>
            <td><asp:TextBox ID="ArticleSubtitle" runat="server" Width="500px"></asp:TextBox></td>
        </tr>
        <tr>
            <td align="right">关键字：</td>
            <td><asp:TextBox ID="ArticleKeywords" runat="server" Width="500px"></asp:TextBox></td>
        </tr>
        <tr>
            <td align="right">所属栏目：</td>
            <td>
                <label id="TopicName" runat="server">请选择</label><asp:HiddenField ID="TopicID" runat="server" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="SelectParent" runat="server" Text="选择" />
            </td>
        </tr>
        <tr>
            <td align="right">文章内容：</td>
            <td>
                <CKEditor:CKEditorControl ID="ArticleBody" runat="server" Height="400px" Skin="v2"></CKEditor:CKEditorControl>
            </td>
        </tr>
        <tr>
            <td align="right">文章附件：</td>
            <td>
                <%
                    if (annexes != null)
                    {
                        foreach (Annex a in annexes)
                        {
                %>
                        <span id="<%=a.ID %>" class="Annex"><%=a.Title%></span>    
                <%
                        }
                    }
                %>

                <asp:Button ID="SelectAnnex" runat="server" Text="添加附件" /><asp:HiddenField ID="AnnexID" runat="server" />
            </td>
        </tr>
        <tr>
            <td align="right">脚注：</td>
            <td>
                <asp:TextBox ID="ArticleFooter" runat="server" Width="500px" TextMode="MultiLine" Height="50px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td align="right">静态模版：</td>
            <td align="left">
                <asp:RadioButtonList ID="ArticleTemplates" runat="server" RepeatDirection="Horizontal" RepeatColumns="4" />
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center"><asp:Button ID="Save" runat="server" Text="保存" 
                    onclick="Save_Click"/></td>
        </tr>
    </table>
</asp:Content>

